package com.dailyblue.java.thread.四个方法;

import lombok.SneakyThrows;

public class DemoC {
    static class C1 implements Runnable {
        private C2 c2;

        public void setC2(C2 c2) {
            this.c2 = c2;
        }

        @Override
        public void run() {
            c2.c();
        }
    }

    static class C2 {
        @SneakyThrows
        public synchronized void c() {
            System.out.println(Thread.currentThread().getName() + "正在执行a方法！");
            Thread.yield();
            System.out.println(Thread.currentThread().getName() + "继续执行a方法！");
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        C2 c = new C2();
        C1 c1 = new C1();
        C1 c2 = new C1();
        C1 c3 = new C1();
        c1.setC2(c);
        c2.setC2(c);
        c3.setC2(c);

        Thread t1 = new Thread(c1);
        Thread t2 = new Thread(c2);
        Thread t3 = new Thread(c3);
        t1.start();
        t2.start();
        t3.start();
    }
}
